/**
 * 
 */
package database.mysql;

import java.sql.Connection;
import java.sql.Statement;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;

/**
 * 
 * @author LionBule 2011-7-4 ����04:46:47.
 */
public class TestWaitTimeout {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		 try {
			 DataSource ds = getDS01();
			 for(int i=0;i<10;i++){
				 System.out.println("test___"+i);
				 testFun(ds, i);
				 Thread.sleep(1000*15);
			 }
		 }catch(Exception e){
			 e.printStackTrace();
		 }
	}
	
	private static void testFun(DataSource ds, int number){
		Connection conn = null;
		Statement stmt = null;
		 try {
	    		conn = ds.getConnection();
	    		stmt = conn.createStatement();
	    		stmt.executeQuery("select * from test_table");
	    		stmt.close();
	    		conn.close();
	    		System.out.println("OK="+number);
		 }catch(Exception e){
			 e.printStackTrace();
		 }
	}
	
	private static DataSource getDS01(){
		BasicDataSource ds = new BasicDataSource();
		ds.setUsername("lionbule");
		ds.setPassword("hello1234");
		ds.setMaxActive(2);
		ds.setTestWhileIdle(true);
		ds.setValidationQuery("select 1");
		//ds.setTimeBetweenEvictionRunsMillis(5*1000);
		ds.setUrl("jdbc:mysql://10.19.0.110:3306/test?rewriteBatchedStatements=true");
		return ds;
	}
}
